import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    meta:{
      title:"未来社区首页",
      auto:true,
      authArr:[0,1,2]
    },
    component: Home
  },
  {
    path: '/login',
    name: 'Login',
    meta:{
      title:"用户登录"
    },
    component: () => import('../views/Login.vue')
  },
  {
    path: '/register',
    name: 'Register',
    meta:{
      title:"用户注册"
    },
    component: () => import('../views/Register.vue')
  },
  {
    path: '/result/:type',
    name: 'Result',
    meta:{
      title:"操作结果"
    },
    component: () => import('../views/Result.vue'),
    props:true
  },
  {
    path:"/topic",
    name: 'Topic',
    meta:{
      title:"话题",
      auth:true,
      authArr:[0,1,2]
    },
    component: () => import('../views/Topic.vue'),
  },
  {
    path:"/post",
    name: 'Post',
    meta:{
      title:"发布新话题",
      auth:true,
      authArr:[0,1,2]
    },
    component: () => import('../views/Post.vue'),
  },
  {
    path:"/topicDetails/:id",
    name: 'TopicDetails',
    meta:{
      title:"话题详情",
      auth:true,
      authArr:[0,1,2]
    },
    component: () => import('../views/TopicDetails.vue'),
    props:true
  },
  {
    path:"/userCenter/:uid",
    name: 'userCenter',
    meta:{
      title:"用户中心",
      auth:true,
      authArr:[0,1,2]
    },
    component: () => import('../views/userCenter.vue'),
    props:true
  },
  {
    path:"/personal",
    name: 'Personal',
    meta:{
      title:"用户中心",
      auth:true,
      authArr:[0,1,2]
    },
    component: () => import('../views/Personal.vue'),
    props:true
  },
  {
    path:"/topicClass",
    name: 'TopicClass',
    meta:{
      title:"话题分类",
      auth:true,
      authArr:[0,1,2]
    },
    component: () => import('../views/TopicClass.vue'),
    props:true
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  if(to.meta.title){
    document.title = to.meta.title
  }
  next()  
  })
export default router
